//
//  BarMoreButtonController.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/12/28.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "BarMoreButtonController.h"

@interface BarMoreButtonController ()

@end

@implementation BarMoreButtonController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"在导航栏上添加多个按钮";
    self.view.backgroundColor = [UIColor whiteColor];
    //注意，如果是在通过navigationController push的 VC，需要通过设置barStyle为UIBarStyleBlack，才会使设置的Status Bar的外观生效
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.11 alpha:1.0];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    

    
    UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(closeAction)];

        UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
        leftButton.backgroundColor = [UIColor clearColor];
        leftButton.frame = CGRectMake(0, 0, 45, 40);
        [leftButton setImage:[UIImage imageNamed:@"LeftButton_back_Icon"] forState:UIControlStateNormal];
        [leftButton setTitle:@"返回" forState:UIControlStateNormal];
//        leftButton.tintColor = [UIColor whiteColor];
        leftButton.autoresizesSubviews = YES;
        leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        leftButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        [leftButton addTarget:self action:@selector(goToBack) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
        
        self.navigationItem.leftBarButtonItems = @[backItem,closeItem];
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(50, 100, 50, 50)];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)closeAction {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)goToBack {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    //恢复到默认设置
    self.navigationController.navigationBar.barTintColor = nil;
    self.navigationController.navigationBar.tintColor = themColor;
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
}

@end
